/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mallasp;

import java.util.ArrayList;
import remixlab.proscene.*;
import processing.core.*;

/**
 *
 * @author DAVINCI
 */
public class MallasP extends PApplet {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        PApplet.main(new String[]{"mallasp.MallasP"});
    }
    Scene scene;
    ArrayList tablaVertices;
    ArrayList tablaPoligonosV;
    ArrayList tablaPoligonosA;
    ArrayList tablaAristas;
    public int method=0;
    public String rep;

    public void setup() {
        size(640, 360, P3D);
        tablaVertices = new ArrayList();
        tablaPoligonosV = new ArrayList();
        tablaPoligonosA = new ArrayList();
        tablaAristas = new ArrayList();
        scene = new Scene(this);
        scene.setGridIsDrawn(false);
        crearPoligonos();
        println(QUADS);

    }

    public void draw() {
       if (rep=="explicita"){
           background(0);
        fill(0, 0, 200);
        beginShape(method);
        vertex(40, 50, 60);
        vertex(10, 4, 9);
        vertex(70, 55, 60);

        endShape(CLOSE);
        fill(200);

        beginShape(method);
        vertex(40, 50, 60);
        vertex(10, 4, 9);
        vertex(40, 30, 78);
        endShape(CLOSE);

        fill(200, 0, 0);

        beginShape(method);
        vertex(10, 4, 9);
        vertex(40, 30, 78);
        vertex(70, 55, 60);
        endShape(CLOSE);
       }
        if (rep=="vertices"){
        
        for (int i = 0; i < tablaPoligonosV.size(); i++) {
                if(i==0)fill(0, 45, 250);
                if(i==1)fill(250,45,0);
                if(i==2)fill(45, 250, 20);
                stroke(255);
                beginShape(method);
                for (int j = 0; j < ((ArrayList) tablaPoligonosV.get(i)).size(); j++) {

                    vertex(((int[]) ((ArrayList) tablaPoligonosV.get(i)).get(j))[0],
                            ((int[]) ((ArrayList) tablaPoligonosV.get(i)).get(j))[1],
                            ((int[]) ((ArrayList) tablaPoligonosV.get(i)).get(j))[2]);
                }
                endShape(CLOSE);
            }}
       if (rep=="aristas"){

        for (int i = 0; i < tablaPoligonosA.size(); i++) {
                if(i==0)fill(0, 45, 250);
                if(i==1)fill(250,45,0);
                if(i==2)fill(45, 250, 20);
                stroke(255);
                beginShape(method);
                for (int j = 0; j <  tablaAristas.size(); j++) {

                    vertex(((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[0][0],
                            ((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[0][1],
                           ((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[0][2]);

                    vertex(((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[1][0],
                            ((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[1][1],
                           ((int[][])((ArrayList) (tablaPoligonosA.get(i))).get(j))[1][2]);
                }
                endShape(CLOSE);
            }
    }

//        
    }

    void crearPoligonos() {

        //*Tabla de Vertices usada para las dos representaciones
        tablaVertices.add(vertice(30, 50, 9));
        tablaVertices.add(vertice(40, 90, 50));
        tablaVertices.add(vertice(70, 55, 30));
        tablaVertices.add(vertice(40, 50, 60));
        ///
        //*Representacion con apuntador a Tabla de vertices
        ArrayList poligono1v = new ArrayList();
        ArrayList poligono2v = new ArrayList();
        ArrayList poligono3v = new ArrayList();
        poligono1v.add(tablaVertices.get(0));
        poligono1v.add(tablaVertices.get(1));
        poligono1v.add(tablaVertices.get(2));
        tablaPoligonosV.add(poligono1v);
        poligono3v.add(tablaVertices.get(3));
        poligono3v.add(tablaVertices.get(0));
        poligono3v.add(tablaVertices.get(1));
        tablaPoligonosV.add(poligono3v);
        poligono2v.add(tablaVertices.get(3));
        poligono2v.add(tablaVertices.get(0));
        poligono2v.add(tablaVertices.get(2));
        tablaPoligonosV.add(poligono2v);

        //*Representacion con apuntador a Tabla de Aristas

        ArrayList poligono1a = new ArrayList();
        ArrayList poligono2a = new ArrayList();
        ArrayList poligono3a = new ArrayList();

        tablaAristas.add(arista((int[])(tablaVertices.get(0)),(int[])tablaVertices.get(1)));
        tablaAristas.add(arista((int[])(tablaVertices.get(1)),(int[])tablaVertices.get(2)));
        tablaAristas.add(arista((int[])(tablaVertices.get(0)),(int[])tablaVertices.get(3)));
        tablaAristas.add(arista((int[])(tablaVertices.get(1)),(int[])tablaVertices.get(2)));
        tablaAristas.add(arista((int[])(tablaVertices.get(1)),(int[])tablaVertices.get(3)));
        tablaAristas.add(arista((int[])(tablaVertices.get(2)),(int[])tablaVertices.get(3)));

        poligono1a.add(tablaAristas.get(0));
        poligono1a.add(tablaAristas.get(1));
        poligono1a.add(tablaAristas.get(3));
        tablaPoligonosA.add(poligono1v);
        poligono2a.add(tablaAristas.get(1));
        poligono2a.add(tablaAristas.get(2));
        poligono2a.add(tablaAristas.get(5));
        tablaPoligonosA.add(poligono1v);
        poligono3a.add(tablaAristas.get(0));
        poligono3a.add(tablaAristas.get(2));
        poligono3a.add(tablaAristas.get(4));
        tablaPoligonosA.add(poligono1v);


        
    }

    private int[] vertice(int x, int y, int z) {
        int[] vertice = {x, y, z};
        return vertice;
    }
    private int[][] arista(int[] v1, int[] v2) {
        int arista[][] = {v1,v2};
        return arista;
    }

    public void keyPressed() {
        if ((key == 'x') || (key == 'X')) {
            tablaVertices.set(0, vertice(4, 5, 0));
        }
//  crearPoligonos();
        if ((key == 't') || (key == 'T')) {
            method=9;
        }
        if ((key == 'P') || (key == 'p')) {
            method=2;
        }
        if ((key == 'l') || (key == 'L')) {
            method=4;
        }
        if ((key == 'S') || (key == 's')) {
            method=10;
        }
        if ((key == 'f') || (key == 'F')) {
            method=11;
        }
         if ((key == 'Q') || (key == 'q')) {
            method=16;
        }
        if ((key == '1')) {
            rep="explicita";
        }
        if ((key == '2')) {
            rep="vertices";
        }
        if ((key == '3')) {
            rep="aristas";
        }

    }
}
